"""
简单测试程序 - 诊断问题2增强版的错误
"""

import time
import numpy as np

def test_basic_import():
    """测试基本导入"""
    print("🧪 测试1: 基本导入")
    try:
        from problem2_solver_enhanced import Problem2SolverEnhanced
        print("   ✅ 导入成功")
        return True
    except Exception as e:
        print(f"   ❌ 导入失败: {e}")
        return False

def test_solver_creation():
    """测试求解器创建"""
    print("\n🧪 测试2: 求解器创建")
    try:
        from problem2_solver_enhanced import Problem2SolverEnhanced
        print("   正在创建求解器...")
        solver = Problem2SolverEnhanced()
        print("   ✅ 求解器创建成功")
        return True, solver
    except Exception as e:
        print(f"   ❌ 求解器创建失败: {e}")
        import traceback
        traceback.print_exc()
        return False, None

def test_layout_simple():
    """测试简单布局生成"""
    print("\n🧪 测试3: 简单布局生成")
    try:
        success, solver = test_solver_creation()
        if not success:
            return False
        
        print("   正在生成布局...")
        positions = solver.stage1_layout_generation(0, 0, 6, 6, 4)
        print(f"   ✅ 生成了 {len(positions)} 个定日镜位置")
        return True
    except Exception as e:
        print(f"   ❌ 布局生成失败: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_efficiency_simple():
    """测试简单效率计算"""
    print("\n🧪 测试4: 简单效率计算")
    try:
        success, solver = test_solver_creation()
        if not success:
            return False
        
        print("   正在计算效率...")
        # 只用一个镜子测试
        mirror_positions = [(150, 0)]
        power = solver.stage4_efficiency_calculation(
            mirror_positions, (0, 0), 6, 6, 4
        )
        print(f"   ✅ 单镜功率: {power:.4f} MW")
        return True
    except Exception as e:
        print(f"   ❌ 效率计算失败: {e}")
        import traceback
        traceback.print_exc()
        return False

def main():
    """主测试函数"""
    print("="*50)
    print("🔬 问题2增强版 - 简单诊断测试")
    print("="*50)
    
    tests = [
        ("基本导入", test_basic_import),
        ("布局生成", test_layout_simple),
        ("效率计算", test_efficiency_simple),
    ]
    
    for test_name, test_func in tests:
        print(f"\n{'='*10} {test_name} {'='*10}")
        try:
            success = test_func()
            if not success:
                print(f"❌ {test_name} 测试失败，停止后续测试")
                break
        except KeyboardInterrupt:
            print(f"\n⚠️  {test_name} 测试被用户中断")
            break
        except Exception as e:
            print(f"❌ {test_name} 测试异常: {e}")
            break
    
    print("\n" + "="*50)
    print("🎯 简单诊断测试完成")
    print("="*50)

if __name__ == "__main__":
    main() 